package nowCoder;

import java.util.Stack;

public class StackWithMin {
	private Stack<Integer> minStack = new Stack<Integer>();
	private Stack<Integer> stack = new Stack<Integer>();
	

    public void push(int node) {
    	stack.push(node);
    	if(minStack.empty()){
    		minStack.push(node);
    	} else{
    		int min = minStack.peek();
    		if(node<=min){
    			minStack.push(node);
    		}
    	}
    }
    
    public void pop() {
    	if(!stack.empty()){
    		int p = stack.pop();
    		if(minStack.peek()==p)
    			minStack.pop();
    	}
    }
    
    public int top() {
    	
    	return stack.peek();
    }
    
    public int min() {
    	return minStack.peek();
    }
    
    public static void main(String[] args){
    	StackWithMin stackWithMin = new StackWithMin();
    	stackWithMin.push(3);
    	stackWithMin.push(2);
    	stackWithMin.push(2);
    	
    	System.out.println(stackWithMin.top());
    	System.out.println(stackWithMin.min());
    	stackWithMin.pop();
    	System.out.println(stackWithMin.top());
    	System.out.println(stackWithMin.min());
    	
    	stackWithMin.pop();
    	System.out.println(stackWithMin.top());
    	System.out.println(stackWithMin.min());
    }
}
